package com.study.manage.dal;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.study.manage.domain.Evaluate;
import com.study.manage.domain.enumm.ReleaseState;

public interface EvaluateRepository extends PagingAndSortingRepository<Evaluate, Long> {


    @Query(nativeQuery = true,
            value = "SELECT Min(created_at),Max(end_at) FROM sa_evaluate where id in (?1)")
    List<Object[]> getBegEndTime(List<Long> evaluateIds);

    Page<Evaluate> findByidIn(List<Long> evaluateIds, Pageable pageable);

    Page<Evaluate> findByUserId(Long userId, Pageable pageable);

    @Query("select t from Evaluate t where t.userId=:userId and (t.state=:state or :state is null)")
    Page<Evaluate> findByUserIdAndState(@Param("userId") Long userId,
            @Param("state") ReleaseState state, Pageable pageable);

    @Query("select t.id from Evaluate t where t.userId=:userId and (t.state=:state or :state is null)")
    List<Long> findIdByUserIdAndState(@Param("userId") Long userId,
            @Param("state") ReleaseState state);

    @Query("select t from Evaluate t where t.beginAt<=:date and t.endAt>=:date and t.state=1")
    List<Evaluate> findByBeginAtAndEndAt(@Param("date") Date date);

}
